package com.shigu.user.action;

import com.google.zxing.WriterException;
import com.shigu.MallResponse;
import com.shigu.PageResponse;
import com.shigu.TokenRequest;
import com.shigu.account.bo.CommissionOrderRequest;
import com.shigu.account.bo.WapCashRequest;
import com.shigu.account.bo.WithdrawRequest;
import com.shigu.account.exception.UtilsAccountException;
import com.shigu.account.service.UserMoneyService;
import com.shigu.account.vo.CommissionInfoResponse;
import com.shigu.account.vo.CommissionOrderVo;
import com.shigu.account.vo.CommissionVo;
import com.shigu.account.vo.WapCashVo;
import com.shigu.exceptions.WapException;
import com.shigu.shareImg.bo.ShareRequest;
import com.shigu.shareImg.service.SnsImgService;
import com.shigu.shareImg.vo.InviteImageResponse;
import com.shigu.shareImg.vo.JointPicResponse;
import com.shigu.user.service.MallTokenService;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/*
 * create by  过儿  2019-05-05
 * 佣金查询新的类
 */
@Controller
@RequestMapping("/wapsjson")
public class UserMoneyController {
    @Autowired
    UserMoneyService userMoneyService;
    @Autowired
    MallTokenService mallTokenService;
    @Autowired
    SnsImgService snsImgService;

    @RequestMapping("getCommissionList")
    @ResponseBody
    public PageResponse<CommissionVo> getCommissionList(TokenRequest request){
        Long mallUserId = mallTokenService.selUserIdByToken(request.getToken());
        return userMoneyService.getCommissionList(mallUserId);
    }

    @RequestMapping("getVoucherConsumptionList")
    @ResponseBody
    public PageResponse<CommissionVo> getVoucherConsumptionList(TokenRequest request){
        Long mallUserId = mallTokenService.selUserIdByToken(request.getToken());
        return userMoneyService.voucherRecord(mallUserId);
    }


    @RequestMapping("getCommissionOrders")
    @ResponseBody
    public PageResponse<CommissionOrderVo> getCommissionOrders(CommissionOrderRequest request){
        Long mallUserId = mallTokenService.selUserIdByToken(request.getToken());
        return userMoneyService.getCommissionOrders(mallUserId,request.getPage(),request.getSize());
    }

    @RequestMapping("getUserCommissionInfo")
    @ResponseBody
    public CommissionInfoResponse getUserCommissionInfo(TokenRequest request){
        Long mallUserId = mallTokenService.selUserIdByToken(request.getToken());
        return userMoneyService.getUserCommissionInfo(mallUserId);
    }

    @RequestMapping("applyWithdraw")
    @ResponseBody
    public MallResponse applyWithdraw(WithdrawRequest request) throws WapException, UtilsAccountException {
        Long mallUserId = mallTokenService.selUserIdByToken(request.getToken());
        return userMoneyService.applyWithdraw(mallUserId,request.getWithdrawAccout(),request.getPsw());
    }

    @RequestMapping("getJointPic")
    @ResponseBody
    public JointPicResponse getJointPic(ShareRequest request) throws WriterException {
        return  snsImgService.getJointPic(request.getItemId(),request.getToken());
    }

    @RequestMapping("getWithdrawRecordList")
    @ResponseBody
    public PageResponse<WapCashVo> getWithdrawRecordList(WapCashRequest request){
        Long mallUserId = mallTokenService.selUserIdByToken(request.getToken());
        return userMoneyService.getWithdrawRecordList(request.getPage(),request.getSize(),mallUserId);
    }
    @RequestMapping("getInviteImgSrc")
    @ResponseBody
    public InviteImageResponse getInviteImgSrc(TokenRequest request) throws WapException {
        Long mallUserId = mallTokenService.selUserIdByToken(request.getToken());
        return snsImgService.getInviteImgSrc(mallUserId);
    }
}
